package com.mall.user.service.impl;

import com.mall.user.model.Areas;
import com.mall.user.mapper.AreasMapper;
import com.mall.user.service.IAreasService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 区域表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@Service
public class AreasServiceImpl extends ServiceImpl<AreasMapper, Areas> implements IAreasService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addAreas(Areas areas){
        return super.save(areas);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String areaid){
        return super.removeById(areaid);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateAreas(Areas areas){
        return super.updateById(areas);
    }

    @Override
    public Areas getById(String areaid){
        return super.getById(areaid);
    }

    @Override
    public List<Areas> selectList(Areas areas){
        return super.list(getQueryWrapper(areas));
    }

    @Override
    public Page<Areas> selectPage(Page<Areas> page, Areas areas){
        return super.page(page, getQueryWrapper(areas));
    }

    public LambdaQueryWrapper<Areas> getQueryWrapper(Areas areas){
        return Wrappers.<Areas>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(areas.getAreaid()), Areas::getAreaid, areas.getAreaid())
            .eq(ObjectUtils.isNotEmpty(areas.getArea()), Areas::getArea, areas.getArea())
            .eq(ObjectUtils.isNotEmpty(areas.getCityid()), Areas::getCityid, areas.getCityid())
        ;
    }
}
